Repository navigation
net: reject immutable onread buffers - #67394
fatihguzeldev wants to merge 2 commits into
Conversation
reject immutable buffers supplied directly or returned by an onread buffer factory before using them for socket reads. emit ERR_INVALID_ARG_VALUE without modifying the backing store. Refs: nodejs#66346 Signed-off-by: Fatih Güzel <fatihguzeldev@gmail.com>
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #67394 +/- ##
==========================================
- Coverage 90.74% 90.60% -0.14%
==========================================
Files 798 801 +3
Lines 280083 281009 +926
Branches 53900 54240 +340
==========================================
+ Hits 254166 254620 +454
- Misses 16217 16564 +347
- Partials 9700 9825 +125
🚀 New features to boost your workflow:
|
| return req; | ||
| } | ||
|
|
||
| function onUserBufferError(stream, buffer) { |
There was a problem hiding this comment.
The name should be a bit specific....
| function onUserBufferError(stream, buffer) { | |
| function destroyWithImmutableArrayBufferError(stream, buffer) { |
| self[kBuffer] = userBuf; | ||
| } | ||
| self._handle.useUserBuffer(userBuf); | ||
| if (setUserBuffer(self, userBuf, true)) |
There was a problem hiding this comment.
Really not a fan of bool arguments, but if we're going to have them, please label call sites to make them clear (we're not consistent with that, at all... would love us to start)
| if (setUserBuffer(self, userBuf, true)) | |
| if (setUserBuffer(self, userBuf, true /*deferError*/)) |
There was a problem hiding this comment.
out of curiosity, is it mainly about readability at the call site, or are there other reasons you tend to avoid boolean parameters?
| streamBaseState, | ||
| } = internalBinding('stream_wrap'); | ||
| const { UV_EOF } = internalBinding('uv'); | ||
| const { isArrayBufferViewImmutable } = internalBinding('util'); |
There was a problem hiding this comment.
It's not available via primordials yet because it is flagged, but there is already an ArrayBuffer.prototype.immutable property that really should be used instead.
There was a problem hiding this comment.
thanks. i was able to deserialize an immutable arraybuffer with the flag off, but the getter isn't available there. would you recommend keeping the native check for that case?
report the error without inspecting the supplied buffer so a custom inspector cannot prevent the socket from closing. cover rejection when the v8 getter is unavailable and when the buffer has a throwing custom inspector. Signed-off-by: Fatih Güzel <fatihguzeldev@gmail.com>
socket reads can currently overwrite immutable storage passed
through onread.buffer, either directly or from a buffer factory.
reject these buffers before they are used for reads and report
ERR_INVALID_ARG_VALUE through the socket's error event.
refs: #66346